package com.xxr.mom.ci.common.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author natsuki_kining
 */
public class TimeUtil {

    public final static String FULL_TIME_PATTERNS = "yyyy-MM-dd HH:mm:ss";
    public final static String DEFAULT_TIME_PATTERNS = "yyyy-MM-dd";

    private final static SimpleDateFormat FULL_SIMPLE_DATE_FORMAT = new SimpleDateFormat(FULL_TIME_PATTERNS);

    /**
     * 时间戳转时间 yyyy-MM-dd HH:mm:ss
     *
     * @param timeStamp 时间戳
     * @return yyyy-MM-dd HH:mm:ss
     */
    public static String timeStampToDate(long timeStamp) {
        return FULL_SIMPLE_DATE_FORMAT.format(timeStamp);
    }

    /**
     * 获取当前时间字符串
     *
     * @return 当前时间字符串
     */
    public static String nowStr() {
        return FULL_SIMPLE_DATE_FORMAT.format(new Date());
    }

    /**
     * localDateTime转字符串
     *
     * @param localDateTime LocalDateTime
     * @return 日期字符串
     */
    public static String formatLocalDateTime(LocalDateTime localDateTime) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERNS);
        return df.format(localDateTime);
    }

    public static String formatFullLocalDateTime(LocalDateTime localDateTime) {
        DateTimeFormatter df = DateTimeFormatter.ofPattern(FULL_TIME_PATTERNS);
        return df.format(localDateTime);
    }
}
